package leetcode;

import entity.ListNode;
import org.junit.Test;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2021/12/21 8:46
 */
public class Test21 {

    /**
     * 将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。
     * <p>
     * 输入：l1 = [1,2,4], l2 = [1,3,4]
     * 输出：[1,1,2,3,4,4]
     */

    @Test
    public void test() {
        ListNode l1 = new ListNode(1, new ListNode(4, new ListNode(5)));
        ListNode l2 = new ListNode(1, new ListNode(3, new ListNode(4)));
        mergeTwoLists(l1, l2);

    }


    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode l1 = new ListNode(-1);
        while (list1 != null && list2 != null) {
            if (list1.val > list2.val) {
                l1.next = list1;
            }
            l1.next = list2;
        }
        return l1;
    }


}
